/*
 * Copyright (c) 2024. hallele, Inc All rights reserved.
 */

package cn.hallele.ms.usercenter.model.repository;

import cn.hallele.mc.sdk.usercenter.common.enums.DeptStatusEnum;
import cn.hallele.ms.usercenter.model.entity.DeptEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

/**
 * hallele_ms_usercenter
 *
 * @author anle5
 * @since 2024/11/12 23:11
 */
public interface DeptRepository extends JpaRepository<DeptEntity, Integer>, JpaSpecificationExecutor<DeptEntity> {
    /**
     * 更新 部门 状态
     *
     * @param id        主键
     * @param oldStatus 老状态
     * @param newStatus 新状态
     * @return 成功条数
     */
    @Modifying()
    @Transactional(rollbackFor = Exception.class)
    @Query(value = "update DeptEntity t set t.status = ?3 where t.id = ?1 and t.status = ?2")
    int updateStatus(Integer id, DeptStatusEnum oldStatus, DeptStatusEnum newStatus);
}
